<!--
 * @Author: your name
 * @Date: 2022-01-29 11:30:57
 * @LastEditTime: 2022-01-29 16:06:10
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\1765.地图最大值.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //暴力检查 超时
        for (let i = 0; i < isWater.length; i++) { //重置为高度
            for (let j = 0; j < isWater[i].length; j++) {
                isWater[i][j] === 1 ? isWater[i][j] = 0 : isWater[i][j] = 1;
            }
        }
        let isbad = true;
        while (isbad) {
            isbad = false;
            for (let i = 0; i < isWater.length; i++) {
                for (let j = 0; j < isWater[i].length; j++) {
                    if (!isWater[i][j]) continue;
                    let top = i - 1 >= 0 ? isWater[i - 1][j] : '';
                    let right = j + 1 < isWater[i].length ? isWater[i][j + 1] : '';
                    let bottom = i + 1 < isWater.length ? isWater[i + 1][j] : '';
                    let left = j - 1 >= 0 ? isWater[i][j - 1] : '';
                    if (top || top === 0) {
                        if (!(top - isWater[i][j] === 0 || top - isWater[i][j] === 1)) continue;
                    }
                    if (right || right === 0) {
                        if (!(right - isWater[i][j] === 0 || right - isWater[i][j] === 1)) continue;
                    }
                    if (bottom || bottom === 0) {
                        if (!(bottom - isWater[i][j] === 0 || bottom - isWater[i][j] === 1)) continue;
                    }
                    if (left || left === 0) {
                        if (!(left - isWater[i][j] === 0 || left - isWater[i][j] === 1)) continue;
                    }
                    isWater[i][j]++;
                    isbad = true;
                }
            }
            if (!isbad) return isWater;
        }
    </script>
    <script>
        //离最近水域的路径值即为该点的高度 超时
        var highestPeak = function (isWater) {
            let waterBox = [];
            for (let i = 0; i < isWater.length; i++) { //重置为高度 找出所有水域
                for (let j = 0; j < isWater[i].length; j++) {
                    if (isWater[i][j] === 1) {
                        isWater[i][j] = 0;
                        waterBox.push([i, j]);
                    } else {
                        isWater[i][j] = 1;
                    }
                }
            }

            for (let i = 0; i < isWater.length; i++) { //
                for (let j = 0; j < isWater[i].length; j++) {
                    if (!isWater[i][j]) continue;
                    let minNum = Number.MAX_VALUE;
                    for (let k = 0; k < waterBox.length; k++) {
                        let result = Math.abs(waterBox[k][0] - i) + Math.abs(waterBox[k][1] - j);
                        if (result < minNum) minNum = result;
                    }
                    isWater[i][j] = minNum;
                }
            }

            return isWater;
        };
    </script>
    <script>
        
    </script>
</body>

</html>